package com.jianda.service;

import com.jianda.commons.content.Content;
import com.jianda.commons.util.ListSaveUtils;
import com.jianda.commons.util.SerialPortUtils;

/**
 * 退出时操作
 */
public class ExitAutoSaveService {

    /*@PreDestroy
    public void destory() {
        try {
            ListSaveUtils.saveStorageList(new DataReceiver().values, Content.path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("销毁方法执行了");
    }*/

    public static void destory() {
        Thread destory = new Thread(() -> {

            ListSaveUtils.saveStorageList(WaveDataService.values, Content.path);
            SerialPortUtils serialPort = SerialPortUtils.getSerialPortUtilsInstance();
            serialPort.closeSerialPort();
        });
        Runtime.getRuntime().addShutdownHook(destory);
    }
}
